package com.xesj.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import com.xesj.model.Role;
import com.xesj.service.RoleServiceI;
import com.xesj.util.PageData;

/**
 * 
* @ClassName : roleController 
* @Description : TODO 
* @author : hnk
* @date : 2018年8月24日 下午4:39:18 
*
 */
@Controller
@RequestMapping("roleController")
public class RoleController extends BaseController {
	@Autowired
	private RoleServiceI roleService;
	
	/**
	 * 
	* @Title : RoleController.java 
	* @Package com.xesj.controller 
	* @Description : TODO
	* @author : hnk  
	* @date :2018年8月24日 下午5:06:43
	* @throws Exception 
	* @retutn : String
	* @version
	 */
	@RequestMapping("/updateRole")
	public String updateRole( Role role){
		PageData result = new PageData();
		
		int count = roleService.updateRole(role);
		if (count!=0) {
			result.put("success", true);
			result.put("msg", "成功执行");
		}
		return JSONArray.toJSONString(result);
		
	}
	
	/**
	 * 
	* @Title : RoleController.java 
	* @Package com.xesj.controller 
	* @Description : TODO
	* @author : hnk  
	* @date :2018年8月24日 下午5:06:51
	* @throws Exception 
	* @retutn : String
	* @version
	 */
	@RequestMapping("/givePermission")
	public String givePermission(){
		PageData result = new PageData();
		PageData pd = getPageData();
		String permissionIdList = pd.getString("permissionIdList");
		String roleId = pd.getString("roleId");
		String[] permissionIds = permissionIdList.split(",");
		 int count = roleService.givePermission(permissionIds,roleId);
		if (true) {
			result.put("success", true);
			result.put("msg", "成功执行");
		}
		return JSONArray.toJSONString(result);
		
	}
	
	
}
